<?php
class Mail {
	public static $cfg;
	/**
	 * 发送邮件调用入口
	 */
	public static function send($cfg) {
		self::setCfg($cfg);
		$clz = 'Mail' . ucfirst(strtolower(self::$cfg['type']));
		$clzFile = FRAMEWORK_MAIL_ROOT . "drivers/{$clz}.class.php";
		if(file_exists($clzFile)) {
			require_once $clzFile;
			//每个send mail的具体类都必须定义mail方法
			return call_user_func(array($clz, 'mail'));
		} else {
			return null;
		}
	}
	
	private static function setCfg($cfg) {
		self::$cfg = require FRAMEWORK_MAIL_ROOT . 'config.php';
		foreach($cfg as $k => $v) {
			if(array_key_exists($k, self::$cfg)) self::$cfg[$k] = $v;
		}
	}
}
?>